import type { ButtonProps } from 'antd-mobile/es/components/button'
import { useBtn } from 'train-fe-component'
import Button from 'antd-mobile/es/components/button'

interface Props extends ButtonProps {
    /** 使用这个方法自动加上Button组件的loading属性 */
    task?: (...args: any) => Promise<any>
    /** 如果异步调用task的时间小于这个loadingDelay的话，不会显示loading */
    loadingDelay?: number
}

const Btn = (props: Props) => {
    const { call, state } = useBtn({
        task: props.task,
        loadingDelay: props.loadingDelay,
    })

    return <Button {...props} onClick={call} loading={state.isLoading} />
}
export default Btn
